<?php

defined('__EAPI_BASE') or define('__EAPI_BASE', dirname(__FILE__));

class EAPIMail extends EAPIxml{
	
	protected $mailXML;
	
	public function __Construct($apiCore,EAPIUser $uObj){
		try{

			parent::__Construct($apiCore);
			$this->mailXML = new SimpleXMLElement($this->getXML('/char/MailMessages.xml.aspx',$uObj));

		}catch (EAPIException $e){
			print $e;
			die();
		}catch (Exception $e){
			print "<pre>".__CLASS__."[{$e->getCode()}]: {$e->getMessage()}\n</pre>";
			die();
		}
		
	}
	public function __Destruct(){}
	
	public function getMail($offset,$limit){
		
		 	if(!$limit){
		 		$limit = count($this->mailXML->result->rowset->{'row'});
		 	}
		 
		
		//create the table for the mail
		$mail[] = "<table class='mail'>";
		for($i=$offset; $i<=$limit+$offset-1;$i++){

			$mail[] = $this->mailXML->result->rowset->{'row'}[$i];

		}
		$mail[] = "</table>";
		
		//print "<pre>";print_r($mailArr);print"</pre>";
		return implode($mail);
	}
	
	private function formatRow($row){
		
		return "<tr><td class='mail-sentDate'>".(string)$row['sentDate']."</td>
						<td class='mail-title'>".(string)$row['title']."</td>
						<td class='mail-senderID'>".(string)$row['senderID']."</td>
						<td class='mail-toCharacterIDs'>".(string)$row['toCharacterIDs']."</td>
						<td class='mail-read'>".(string)$row['read']."</td></tr>";
	}
	
};